package wfmanage.action;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.util.MyLog;

import edu.wfmanage.models.Claim;
import edu.wfmanage.models.User;
/**
 Author: Satya Deepthi Bhagi
 */
public class newRequest extends ActionSupport{
	
	private static final long serialVersionUID = 1L;
	private String mode ="";
	private String travelonDate;
	private String ticketNor="";
	private int distance;
	private Date travelDate=null;
	private String source="";
	private String destination="";
	private int fare;
	private int limit =0;
	private String username="";
	private int LTALimit;
	private List<User> userDetails;
	String toList="";
	public String execute() throws Exception {
		if (this.ticketNor.isEmpty()) {
			Map<String, Object> session = ActionContext.getContext().getSession();
			User user = (User) session.get("user");
			if (user == null) {
				user = new User();
			}
			MyLog.log("Initial page for Raising New LTA request");
			LTALimit=user.getLTALimit();
			return "initial_entry";
		}else{
			Map<String, Object> session = ActionContext.getContext().getSession();
			User user = (User) session.get("user");
			if (user == null) {
				user = new User();
			}
			
			Claim claim=new Claim();
			claim.setDestination(destination);
			claim.setDistance(distance);
			claim.setFare(fare);
			claim.setLimit(limit);
			claim.setMode(mode);
			claim.setSource(source);
			claim.setTicketNor(ticketNor);
			claim.setTravelDate(travelDate);
			claim.setUserid(user.getUserid());
			claim.insert();
			username=user.getUsername();
			userDetails=User.userDetails("where emp_role ='vefication_dpt'");
			//MyLog.log("user Travelledd on"+travelonDate);
			email mail=new email();
			for(User u: userDetails){
				MyLog.log("user is"+u.getEmailid());
		//toList+="\""+u.getEmailid()+"\", ";
					mail.sendmail(u.getUsername(),u.getEmailid(),"vefication_dpt",0,"NA");
					MyLog.log("An email has been sent to"+u.getEmailid());
			}
			
			
		return "claimsuccess";
	}

}
	
	
	public int getLTALimit() {
		return LTALimit;
	}


	public void setLTALimit(int lTALimit) {
		LTALimit = lTALimit;
	}


	public String getusername() {
		return username;
	}


	public void setusername(String username) {
		this.username = username;
	}


	public Date getTravelDate() {
		return travelDate;
	}


	public void setTravelDate(Date travelDate) {
		this.travelDate = travelDate;
	}


	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}


	public int getFare() {
		return fare;
	}

	public void setFare(int fare) {
		this.fare = fare;
	}

	public String getMode() {
		return mode;
	}

	public void setMode(String mode) {
		this.mode = mode;
	}

	public String getTicketNor() {
		return ticketNor;
	}

	public void setTicketNor(String ticketNor) {
		this.ticketNor = ticketNor;
	}

	
	public int getDistance() {
		return distance;
	}

	public void setDistance(int distance) {
		this.distance = distance;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public String getDestination() {
		return destination;
	}

	public void setDestination(String destination) {
		this.destination = destination;
	}


	public String getTravelonDate() {
		return travelonDate;
	}


	public void setTravelonDate(String travelonDate) {
		this.travelonDate = travelonDate;
	}
	

}